//
//  BaseViewController.swift
//  JMWB
//
//  Created by 个人电脑 on 16/3/14.
//  Copyright © 2016年 个人电脑. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {

    lazy var visitorView : VisitorView = VisitorView.visitorView()
    //判断是否是登陆界面 如果是false代表着没有登陆显示访客视图 如果是true代表着已经登陆进入首页
//    var isLogin : Bool = false
//    var isLogin : Bool = true
    var isLogin : Bool = UserAccountViewModel.shareIntance.isLogin

    
    override func loadView() {
        isLogin ? super.loadView() : setupVisitorView()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
}
extension BaseViewController{

   private func setupVisitorView(){
    view = visitorView
    
    navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "registerBtnCilck")
    navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: "loginBtnClick")
    
    visitorView.registerBtn.addTarget(self, action: "registerBtnCilck", forControlEvents: .TouchUpInside)
    visitorView.loginBtn.addTarget(self, action: "loginBtnClick", forControlEvents: .TouchUpInside)
    }
}
extension BaseViewController{

    @objc private func registerBtnCilck(){
        print("registerBtnCilck")
    }
    @objc private func loginBtnClick(){
//    print("loginBtnClick")
        // 1.创建授权页面
        let oauthVC = OAuthViewController()
        // 2.包装导航控制器
        let oauthNav = UINavigationController(rootViewController: oauthVC)
        // 3.弹出授权页面
        presentViewController(oauthNav, animated: true, completion: nil)
    }
}